package cn.hinglo.permission.controller;

import lombok.extern.slf4j.Slf4j;

import javax.websocket.OnMessage;
import javax.websocket.OnOpen;
import javax.websocket.Session;
import javax.websocket.server.PathParam;
import javax.websocket.server.ServerEndpoint;

/**
 * @author HingLo
 * @createTime: 2020/3/19 21:43
 * @description: websocket
 */
@ServerEndpoint("/websocket.ws/{username}")
@Slf4j
public class WebSocketController {

    @OnOpen
    public void open(@PathParam("username") String username, Session session) {
        System.out.println(username);
        System.out.println("打开链接,session:" + session.getId());
    }


    @OnMessage
    public void onMessage(String params, Session session) throws Exception {
        //获取服务端到客户端的通道
        log.info("收到来自" + session.getId() + "的消息" + params);
        session.getBasicRemote().sendText("我收到了你的信息");
    }

}
